// @Time ： 2021/10/20 上午11:20
// @Auth ： luo
// @File ：decimal_vertical.js
// @IDE ：vsCode

//判断两个数的加减乘除
class EquationClassify {
    constructor(equation_mat){
        this.equation_mat = equation_mat
    }
    
    main(){
        var resArry = new Object()
        if (this.equation_mat.indexOf('+')>0){
            var equation_mat_split = this.equation_mat.split('+')
            resArry = this.AddTwoNumber(equation_mat_split[0],equation_mat_split[1])
            resArry.operator = '+'
            return resArry
        }
        else if (this.equation_mat.indexOf('-')>0){
            var equation_mat_split = this.equation_mat.split('-')
            resArry = this.SubTwoNumber(equation_mat_split[0],equation_mat_split[1])
            resArry.operator = '-'
            return resArry
        }
        else if (this.equation_mat.indexOf('x')>0 || this.equation_mat.indexOf('X')>0 ||this.equation_mat.indexOf('*')>0){
            var equation_mat_split,operator;
            if(this.equation_mat.indexOf('x')>0){
                equation_mat_split = this.equation_mat.split('x')
                operator = 'x'
            }
            else if(this.equation_mat.indexOf('X')>0){
                equation_mat_split = this.equation_mat.split('X')
                operator = 'X'
            }
            else if(this.equation_mat.indexOf('*')>0){
                equation_mat_split = this.equation_mat.split('*')
                operator = '*'
            }
            resArry = this.MulTwoNumber(equation_mat_split[0],equation_mat_split[1])
            resArry.operator = operator
            return resArry
        }
        
        else if (this.equation_mat.indexOf('÷')>0 || this.equation_mat.indexOf('/')>0){
            var equation_mat_split,operator;
            if(this.equation_mat.indexOf('÷')>0){
                equation_mat_split = this.equation_mat.split('÷')
                operator = '÷'
            }
            else if(this.equation_mat.indexOf('/')>0){
                equation_mat_split = this.equation_mat.split('/')
                operator = '/'
            }
        
            resArry = this.ExcTwoNumber(equation_mat_split[0],equation_mat_split[1])
            resArry.operator = operator
            return resArry
        }
        else{
            resArry.code = -1
            resArry.msg = '未知运算符'
            return resArry
        }
    }

    AddTwoNumber(first_num,second_num){
        var returnObj = new Object();
        returnObj.code = 200 
        returnObj.data = new Object();
        //判断两个参数是否为数字
        var first_to_number,second_to_number
        try {
            first_to_number = eval(first_num)
            second_to_number = eval(second_num)
        } catch (error) {
            returnObj.code = -1
            returnObj.msg = "存在参数不为数字"
            return returnObj
        }
        if (first_to_number == null || second_to_number == null){
            returnObj.code = -1
            returnObj.msg = "存在参数不为数字"
            return returnObj
        }
        // 判断两个数类型 (int float)
        var first_num_indexOf = first_num.indexOf('.')
        var second_num_indexOf = second_num.indexOf('.')
        var first_arr = first_num.split('')
        var second_arr = second_num.split('')
        var res = (first_to_number + second_to_number).toString();
        if(first_num_indexOf == -1 && second_num_indexOf > 0){
            var res_indexOf_index = res.indexOf('.') //整数部分长度
            var res_length = res.length
            var first_len = res_indexOf_index-first_arr.length;
            for (let index = 0; index < first_len; index++) {
                first_arr.unshift(null)
            }
            for (let index = 0; index < res_length-res_indexOf_index; index++) {
                first_arr.push(null)
            }
            var second_len = res_indexOf_index - second_arr.indexOf('.')
            for (let index = 0; index < second_len; index++) {
                second_arr.unshift(null)
            }
            var wei = new Array();
            if (first_arr.length != second_arr.length){
                returnObj.code = -1;
                returnObj.msg = "算法错误"
                return returnObj
            }
            for (let index = first_arr.length-1; index >= 0; index--) {
                const first_one = first_arr[index];
                const second_one = second_arr[index];
                if(first_num_indexOf == null && second_one == null || first_num_indexOf == null && second_one == '.'){
                    wei.unshift('0')
                }
                else {
                    try {
                        var eval_res = eval(first_one) + eval(second_one)
                        if (wei.length != 0){
                            eval_res +=  eval(wei[0])
                        }
                        if(eval_res >= 10){
                            wei.unshift('1')
                        }else{
                            wei.unshift('0')
                        }
                        
                    } catch (error) {
                        wei.unshift('0')
                    }  
                }
            }
            var remove_first = wei.shift()
            wei.push(remove_first)
            var decimal_index = second_arr.indexOf('.')
            wei[decimal_index] = ''
            returnObj.data.first_arr = first_arr
            returnObj.data.second_arr = second_arr
            returnObj.data.position_arr = wei
            returnObj.data.res = res.split('')
            return returnObj
        }
        else if (first_num_indexOf > 0  && second_num_indexOf == -1 ){
            [first_arr,second_arr] = [second_arr,first_arr]
            var res_indexOf_index = res.indexOf('.') //整数部分长度
            var res_length = res.length
            var first_len = res_indexOf_index-first_arr.length;
            for (let index = 0; index < first_len; index++) {
                first_arr.unshift(null)
            }
            for (let index = 0; index < res_length-res_indexOf_index; index++) {
                first_arr.push(null)
            }
            var second_len = res_indexOf_index - second_arr.indexOf('.')
            for (let index = 0; index < second_len; index++) {
                second_arr.unshift(null)
            }
            var wei = new Array();
            if (first_arr.length != second_arr.length){
                returnObj.code = -1;
                returnObj.msg = "算法错误"
                return returnObj
            }
            for (let index = first_arr.length-1; index >= 0; index--) {
                const first_one = first_arr[index];
                const second_one = second_arr[index];
                if(first_num_indexOf == null && second_one == null || first_num_indexOf == null && second_one == '.'){
                    wei.unshift('0')
                }
                else {
                    try {
                        var eval_res = eval(first_one) + eval(second_one)
                        if (wei.length != 0){
                            eval_res +=  eval(wei[0])
                        }
                        if(eval_res >= 10){
                            wei.unshift('1')
                        }else{
                            wei.unshift('0')
                        }
                        
                    } catch (error) {
                        wei.unshift('0')
                    }  
                }
            }
            var remove_first = wei.shift()
            wei.push(remove_first)
            var decimal_index = second_arr.indexOf('.')
            wei[decimal_index] = ''
            returnObj.data.first_arr = second_arr
            returnObj.data.second_arr = first_arr
            returnObj.data.position_arr = wei
            returnObj.data.res = res.split('')
            return returnObj
        }
        else if (first_num_indexOf > 0 && second_num_indexOf > 0) {// float + float 精度丢失   
            var first_split = first_num.split('.')
            var second_split = second_num.split('.')
            var max_decimal_places = Math.max(first_split[1].length,second_split[1].length)//获取结果小数点位数(判断两个小数最高位数)
            var max_int_places = (eval(first_split[0]) + eval(second_split[0])).toString().length    //获取结果整数部分位数(判断两个整数部分最高位数)
            var res_arr = new Array()
            var wei = new Array()
            //整数部分前面补充null
            for (let index = 0; index < max_int_places - first_split[0].length; index++) {
            first_arr.unshift(null)   
            }
            for (let index = 0; index < max_int_places - second_split[0].length; index++) {
                second_arr.unshift(null)   
            }
            //小数后面补充null
            for (let index = 0; index < max_decimal_places - first_split[1].length; index++) {
                first_arr.push(null)   
            }
            for (let index = 0; index < max_decimal_places - second_split[1].length; index++) {
                second_arr.push(null)   
            }
            if (first_arr.length != second_arr.length){
                returnObj.code = -1;
                returnObj.msg = "算法错误"
                return returnObj
            }
            //两个数组对应数值相加
            for (let index = first_arr.length-1; index >= 0; index--) {
                const first_one = first_arr[index];
                const second_one = second_arr[index];
                if(first_one != '.' && second_one != '.'){
                    var res_one;
                    if(index == first_arr.length-1){
                        res_one = eval(first_one) + eval(second_one)
                    
                    }else{
                        res_one = eval(first_one) + eval(second_one) + eval(wei[0])
                    }
                    res_one >= 10 ? wei.unshift('1') : wei.unshift('0')
                    res_arr.unshift(res_one)
                    
                }
                
            }
            // 处理得到的结果数组
            for (let index = 0; index < res_arr.length; index++) {
                const element = res_arr[index];
                if(index==0 && element==10){
                    var remove_first = res_arr.shift().toString()
                    res_arr.unshift('1')
                    res_arr.unshift('0')
                }
                else if (element >= 10){
                    res_arr[index] = element.toString()[1]
                }else{
                    res_arr[index] = element.toString()
                }
            }
            var decimal_index = first_arr.indexOf('.')
            res_arr.splice(decimal_index, 0, '.')
            var remove_first = wei.shift()
            wei.push(remove_first)
            wei.splice(decimal_index, 0, '')
            returnObj.data.first_arr = first_arr
            returnObj.data.second_arr = second_arr
            returnObj.data.position_arr = wei
            returnObj.data.res = res_arr
            return returnObj
        }
        return returnObj
    }

    SubTwoNumber(first_num,second_num){
        var returnObj = new Object();
        returnObj.code = 200 
        returnObj.data = new Object();
        var first_to_number,second_to_number
        try {
            first_to_number = eval(first_num)
            second_to_number = eval(second_num)
        } catch (error) {
            returnObj.code = -1
            returnObj.msg = "存在参数不为数字"
            return returnObj
        }
        if (first_to_number == null || second_to_number == null){
            returnObj.code = -1
            returnObj.msg = "存在参数不为数字"
            return returnObj
        }
        if (first_to_number < second_to_number){
            returnObj.code = -1
            returnObj.msg = "第一个数不能小于第二个数"
            return returnObj
        }
        // 判断两个数类型 (int float)
        var first_num_indexOf = first_num.indexOf('.')
        var second_num_indexOf = second_num.indexOf('.')
        var first_arr = first_num.split('')
        var second_arr = second_num.split('')
        var res_arr = new Array()
        var wei = new Array()
        if(first_num_indexOf == -1 && second_num_indexOf > 0){ // int-float
            var second_int_len = second_num_indexOf
            var second_decima_len = second_arr.length - second_int_len
            for (let index = 0; index < second_decima_len; index++) {
                first_arr.push(null)
            }
            for (let index = 0; index < first_num.length - second_int_len; index++) {
                second_arr.unshift(null)
            }
            if (first_arr.length != second_arr.length){
                returnObj.code = -1;
                returnObj.msg = "算法错误"
                return returnObj
            }
            for (let index = first_arr.length-1; index >= 0; index--) {
                const first_one = first_arr[index];
                const second_one = second_arr[index];
                if(second_one != '.'){
                    var res_one = eval(first_one) - eval(second_one)
                    if(res_one>=0){
                        res_arr.unshift(res_one)
                        wei.unshift('0')
                    }else{
                        res_arr.unshift(res_one+10)
                        wei.unshift('1')
                    }
                }
            }
            var remove_first = wei.shift()
            wei.push(remove_first)
            for (let index = 0; index < res_arr.length; index++) {
                const element = res_arr[index];
                if (element=='10'){
                    res_arr[index] = '0'
                }else{  
                    res_arr[index] = (eval(element)-eval(wei[index])).toString()   
                }   
            }
            var decimal_index = second_arr.indexOf('.')
            res_arr.splice(decimal_index, 0, '.')
            wei.splice(decimal_index, 0, '')
            for (let index = 0; index < res_arr.length; index++) {
                const element = res_arr[index];
                if (element == '0' && res_arr[index+1] == '.'|| element!='0'){
                    break
                }else{
                    res_arr[index] = null
                }               
            }
            returnObj.data.position_arr = wei
            returnObj.data.first_arr = first_arr
            returnObj.data.second_arr = second_arr
            returnObj.data.res = res_arr
            return returnObj
        }
        else if (first_num_indexOf > 0  && second_num_indexOf == -1 ){ //float-int
            var first_int_len = first_num_indexOf
            var first_decima_len = first_arr.length - first_int_len;
        
            for (let index = 0; index < first_int_len - second_arr.length; index++) {
                second_arr.unshift(null)   
            }
            for (let index = 0; index < first_decima_len; index++) {
                second_arr.push(null)   
            }
            if (first_arr.length != second_arr.length){
                returnObj.code = -1;
                returnObj.msg = "算法错误"
                return returnObj
            }
            for (let index = first_arr.length-1; index >= 0; index--) {
                const first_one = first_arr[index];
                const second_one = second_arr[index];
                if(first_one != '.'){
                    var res_one = eval(first_one) - eval(second_one)
                    if(res_one >= 0){
                        res_arr.unshift(res_one)
                        wei.unshift('0')
                    }
                    else{
                        res_arr.unshift(res_one+10)
                        wei.unshift('1')
                    }
                }
                
            }
            var remove_first = wei.shift()
            wei.push(remove_first)
            for (let index = 0; index < res_arr.length; index++) {
                const element = res_arr[index];
                res_arr[index] = (eval(element)-eval(wei[index])).toString()
            }
            var decimal_index = first_arr.indexOf('.')
            res_arr.splice(decimal_index, 0, '.')
            wei.splice(decimal_index, 0, '')
            for (let index = 0; index < res_arr.length; index++) {
                const element = res_arr[index];
                if (element == '0' && res_arr[index+1] == '.'|| element!='0'){
                    break
                }else{
                    res_arr[index] = null
                }               
            }
        
            returnObj.data.position_arr = wei
            returnObj.data.first_arr = first_arr
            returnObj.data.second_arr = second_arr
            returnObj.data.res = res_arr
            return returnObj
        }
        else if (first_num_indexOf > 0 && second_num_indexOf > 0) {// float - float 精度丢失   
            var first_split = first_num.split('.')
            var second_split = second_num.split('.')
            var max_decimal_places = Math.max(first_split[1].length,second_split[1].length)//获取结果小数点位数(判断两个小数最高位数)
            var max_int_places = Math.max(first_split[0].length,second_split[0].length)    //获取结果整数部分位数(判断两个整数部分最高位数)
            var res_arr = new Array()
            var wei = new Array()
            //整数部分前面补充null
            for (let index = 0; index < max_int_places - first_split[0].length; index++) {
            first_arr.unshift(null)   
            }
            for (let index = 0; index < max_int_places - second_split[0].length; index++) {
                second_arr.unshift(null)   
            }
            //小数后面补充null
            for (let index = 0; index < max_decimal_places - first_split[1].length; index++) {
                first_arr.push(null)   
            }
            for (let index = 0; index < max_decimal_places - second_split[1].length; index++) {
                second_arr.push(null)   
            }
            if (first_arr.length != second_arr.length){
                returnObj.code = -1;
                returnObj.msg = "算法错误"
                return returnObj
            }
            for (let index = first_arr.length-1; index >= 0; index--) {
                const first_one = first_arr[index];
                const second_one = second_arr[index];
                if(first_one != '.'){
                    var res_one = eval(first_one) - eval(second_one)
                    if(res_one >= 0){
                        res_arr.unshift(res_one)
                        wei.unshift('0')
                    }
                    else{
                        res_arr.unshift(res_one+10)
                        wei.unshift('1')
                    }
                }
                
            }
            var remove_first = wei.shift()
            wei.push(remove_first)
            for (let index = 0; index < res_arr.length; index++) {
                const element = res_arr[index];
                res_arr[index] = (eval(element)-eval(wei[index])).toString()
            }
            var decimal_index = first_arr.indexOf('.')
            res_arr.splice(decimal_index, 0, '.')
            
            wei.splice(decimal_index, 0, '.')
            for (let index = 0; index < res_arr.length; index++) {
                const element = res_arr[index];
                if (element == '0' && res_arr[index+1] == '.'|| element!='0'){
                    break
                }else{
                    res_arr[index] = null
                }               
            }
            returnObj.data.position_arr = wei
            returnObj.data.first_arr = first_arr
            returnObj.data.second_arr = second_arr
            returnObj.data.res = res_arr
        }
        return returnObj
        
    }

    MulTwoNumber(first_num,second_num){
        var returnObj = new Object();
        returnObj.code = 200 
        returnObj.data = new Object();
        var first_to_number,second_to_number
        try {
            first_to_number = eval(first_num)
            second_to_number = eval(second_num)
        } catch (error) {
            returnObj.code = -1
            returnObj.msg = "存在参数不为数字"
            return returnObj
        }
        // 判断两个数类型 (int float)
        var first_num_indexOf = first_num.indexOf('.')
        var second_num_indexOf = second_num.indexOf('.')
        var first_arr = first_num.split('')
        var second_arr = second_num.split('')
        var calculation_process = new Array();
        var calculation_wei = new Array();
        if(first_num_indexOf == -1 && second_num_indexOf > 0){ // int*float
            var second_decima_len = second_arr.length-second_num_indexOf-1;//第二个数组小数点位数
            second_arr.splice(second_num_indexOf,1)
            var first_arr_to_num = Number(first_arr.join(''))
            var second_arr_to_num = Number(second_arr.join(''))
            var res_arr = (first_arr_to_num * second_arr_to_num).toString().split('')
            //获取运算过程
            for (let index = second_arr.length-1; index >= 0; index--) {
                var res_one = new Array()
                for (let index2 = first_arr.length-1; index2 >= 0; index2--) {
                    const first_one = Number(first_arr[index2])
                    const second_one = Number(second_arr[index])
                    res_one.unshift(first_one*second_one)
                }
                calculation_process.push(res_one)
            }
            //重新整合运算过程，及其进位
            for (let index = 0; index < calculation_process.length; index++) {
                const element = calculation_process[index];
                const wei_one = new Array();
                for (let index2 = element.length-1; index2 >= 0; index2--) {
                    const element_one = element[index2];
                    const element_one_string = element_one.toString();
                    if (element_one >= 10){
                    const element_one_left = element_one_string[0]
                    const element_one_right = element_one_string[1]     
                    element[index2] = element_one_right
                    if(index2>0){
                        element[index2-1] += eval(element_one_left)
                    }
                    else{
                            element.unshift(element_one_left)
                    }
                    wei_one.unshift(element_one_left)
                    }else{
                        element[index2] = element[index2].toString()
                        wei_one.unshift('0')
                    }
                    
                }
            
                calculation_wei.push(wei_one)
                
            }
            //一位整数删除运算过程
            if (first_arr.length == 1 || second_arr.length == 1){calculation_wei = [];calculation_process=[]}
            //所有数组处理添加null位数对齐
            for (let index = 0; index < calculation_process.length; index++) {
                const element = calculation_process[index];
                const wei = calculation_wei[index]
                for (let index2 = 0; index2 < index; index2++) {
                    element.push(null) 
                    wei.push(null)
                }
            }
            for (let index = 0; index < calculation_process.length; index++) {
                const element = calculation_process[index];
                const wei = calculation_wei[index]
                const add_num = res_arr.length-element.length
                const wei_num = res_arr.length - wei.length  
                for (let index2 = 0; index2 < add_num; index2++) {
                    element.unshift(null)  
                }
                for (let index3 = 0; index3 < wei_num; index3++) {
                    wei.unshift(null)   
                }
            }
            //所有数组'.' 添加对应''
            for (let index = 0; index < calculation_process.length; index++) {
                const element = calculation_process[index];
                const wei = calculation_wei[index]
                element.splice(element.length-second_decima_len,0,'')
                wei.splice(wei.length-second_decima_len,0,'')
            }
            first_arr.splice(first_arr.length - second_decima_len,0,'')
            second_arr.splice(second_arr.length - second_decima_len,0,'.')
            res_arr.splice(res_arr.length - second_decima_len,0,'.')
            if(res_arr[0] == '.'){
                res_arr.unshift('0')
            }
            //first_arr second_arr befor add null
            var first_add_num = res_arr.length - first_arr.length
            for (let index = 0; index < first_add_num; index++) {
            first_arr.unshift(null)
            }
            var second_add_num = res_arr.length - second_arr.length
            for (let index = 0; index < second_add_num; index++) {
                second_arr.unshift(null)
            }
            var new_pro = new Array()
            
            for (let index = 0; index < calculation_process.length; index++) {
                const element = calculation_process[index];
                var num_count = 0
                for (let index2 = 0; index2 < element.length; index2++) {
                    const element2 = element[index2];
                    if(element2 == '0' || element2=='' || element2==null || element2=='.'){
                        num_count+=1
                    }
                }
                if(num_count != element.length){
                    new_pro.push(calculation_process[index])
                }
            }
            returnObj.data.first_arr = first_arr
            returnObj.data.second_arr = second_arr
            returnObj.data.position_arr = calculation_wei
            returnObj.data.calculation_process = new_pro
            returnObj.data.res = res_arr    
        }
        else if (first_num_indexOf > 0  && second_num_indexOf == -1 ){ //float*int
            [first_arr,second_arr] = [second_arr,first_arr]
            var second_decima_len = second_arr.length-second_arr.indexOf('.')-1;//第二个数组小数点位数
            second_arr.splice(second_arr.indexOf('.'),1)
            var first_arr_to_num = eval(first_arr.join(''))
            var second_arr_to_num = eval(second_arr.join(''))
            var res_arr = (first_arr_to_num * second_arr_to_num).toString().split('')
            //获取运算过程
            for (let index = first_arr.length-1; index >= 0; index--) {
                var res_one = new Array()
                for (let index2 = second_arr.length-1; index2 >= 0; index2--) {
                    const first_one = eval(second_arr[index2])
                    const second_one = eval(first_arr[index])
                    res_one.unshift(first_one*second_one)
                }
                calculation_process.push(res_one)
            }
            //重新整合运算过程，及其进位
            for (let index = 0; index < calculation_process.length; index++) {
                const element = calculation_process[index];
                const wei_one = new Array();
                for (let index2 = element.length-1; index2 >= 0; index2--) {
                    const element_one = element[index2];
                    const element_one_string = element_one.toString();
                    if (element_one >= 10){
                    const element_one_left = element_one_string[0]
                    const element_one_right = element_one_string[1]     
                    element[index2] = element_one_right
                    if(index2>0){
                        element[index2-1] += eval(element_one_left)
                    }
                    else{
                            element.unshift(element_one_left)
                    }
                    wei_one.unshift(element_one_left)
                    }else{
                        element[index2] = element[index2].toString()
                        wei_one.unshift('0')
                    }
                    
                }
            
                calculation_wei.push(wei_one)
                
            }
            //一位整数删除运算过程
            if (first_arr.length == 1 || second_arr.length == 1){calculation_wei = [];calculation_process=[]}
            //所有数组处理添加null位数对齐
            for (let index = 0; index < calculation_process.length; index++) {
                const element = calculation_process[index];
                const wei = calculation_wei[index]
                for (let index2 = 0; index2 < index; index2++) {
                    element.push(null) 
                    wei.push(null)
                }
            }
            for (let index = 0; index < calculation_process.length; index++) {
                const element = calculation_process[index];
                const wei = calculation_wei[index]
                const add_num = res_arr.length-element.length
                const wei_num = res_arr.length - wei.length  
                for (let index2 = 0; index2 < add_num; index2++) {
                    element.unshift(null)  
                }
                for (let index3 = 0; index3 < wei_num; index3++) {
                    wei.unshift(null)   
                }
            }
            //所有数组'.' 添加对应null
            for (let index = 0; index < calculation_process.length; index++) {
                const element = calculation_process[index];
                const wei = calculation_wei[index]
                element.splice(element.length-second_decima_len,0,'')
                wei.splice(wei.length-second_decima_len,0,'')
            }
            first_arr.splice(first_arr.length - second_decima_len,0,'')
            second_arr.splice(second_arr.length - second_decima_len,0,'.')
            res_arr.splice(res_arr.length - second_decima_len,0,'.')
            if(res_arr[0] == '.'){
                res_arr.unshift('0')
            }
            //first_arr second_arr befor add null
            var first_add_num = res_arr.length - first_arr.length
            for (let index = 0; index < first_add_num; index++) {
            first_arr.unshift(null)
            }
            var second_add_num = res_arr.length - second_arr.length
            for (let index = 0; index < second_add_num; index++) {
                second_arr.unshift(null)
            }
            var new_pro = new Array()
            for (let index = 0; index < calculation_process.length; index++) {
                const element = calculation_process[index];
                var num_count = 0
                for (let index2 = 0; index2 < element.length; index2++) {
                    const element2 = element[index2];
                    if(element2 == '0' || element2=='' || element2==null || element2=='.'){
                        num_count+=1
                    }
                }
                if(num_count != element.length){
                    new_pro.push(calculation_process[index])
                }
            }
            returnObj.data.first_arr = second_arr
            returnObj.data.second_arr = first_arr
            returnObj.data.position_arr = calculation_wei
            returnObj.data.calculation_process = new_pro
            returnObj.data.res = res_arr
            
            
        }
        else if (first_num_indexOf > 0 && second_num_indexOf > 0) {// float*float 精度丢失   
            var first_decima_len = first_arr.length - first_num_indexOf-1; // 第1个数组小数点位数
            var second_decima_len = second_arr.length - second_num_indexOf -1; // 第2个数组小数点位数
            var res_decima_len = first_decima_len + second_decima_len //结果小数点位数
            //俩个数组删除小数点
            first_arr.splice(first_num_indexOf,1)
            second_arr.splice(second_num_indexOf,1)
            //整数求结果
            var first_arr_to_num = Number(first_arr.join(''))
            var second_arr_to_num = Number(second_arr.join(''))
            var res_arr = (first_arr_to_num * second_arr_to_num).toString().split('')
            //获取运算过程
            for (let index = second_arr.length-1; index >= 0; index--) {
                var res_one = new Array()
                for (let index2 = first_arr.length-1; index2 >= 0; index2--) {
                    const first_one = Number(first_arr[index2])
                    const second_one = Number(second_arr[index])
                    res_one.unshift(first_one*second_one)
                }
                calculation_process.push(res_one)
            }
            //重新整合运算过程，及其进位
            for (let index = 0; index < calculation_process.length; index++) {
                const element = calculation_process[index];
                const wei_one = new Array();
                for (let index2 = element.length-1; index2 >= 0; index2--) {
                    const element_one = element[index2];
                    const element_one_string = element_one.toString();
                    if (element_one >= 10){
                    const element_one_left = element_one_string[0]
                    const element_one_right = element_one_string[1]     
                    element[index2] = element_one_right
                    if(index2>0){
                        element[index2-1] += eval(element_one_left)
                    }
                    else{
                            element.unshift(element_one_left)
                    }
                    wei_one.unshift(element_one_left)
                    }else{
                        element[index2] = element[index2].toString()
                        wei_one.unshift('0')
                    }
                    
                }
            
                calculation_wei.push(wei_one)
                
            }
            //一位整数删除运算过程
            if (first_arr.length == 1 || second_arr.length == 1){calculation_wei = [];calculation_process=[]}
            for (let index = 0; index < calculation_process.length; index++) {
                const element = calculation_process[index];
                const wei = calculation_wei[index]
                for (let index2 = 0; index2 < index; index2++) {
                    element.push(null) 
                    wei.push(null)
                }
            }
            for (let index = 0; index < calculation_process.length; index++) {
                const element = calculation_process[index];
                const wei = calculation_wei[index]
                const add_num = res_arr.length-element.length
                const wei_num = res_arr.length - wei.length  
                for (let index2 = 0; index2 < add_num; index2++) {
                    element.unshift(null)  
                }
                for (let index3 = 0; index3 < wei_num; index3++) {
                    wei.unshift(null)   
                }
            }
            //第一个数组,第二个数组,结果每个'.'添加对应的''三种情况,
            //第一个数组长度和第二个数组长度 1.相同 2.不同 
            //第一个数组长度和第二个数组长度一定小于结果的长度
            if(first_decima_len == second_decima_len){
                for (let index = 0; index < calculation_process.length; index++) {
                    const element = calculation_process[index];
                    const wei = calculation_wei[index]
                    element.splice(element.length-second_decima_len,0,'')
                    wei.splice(wei.length-second_decima_len,0,'')
                }
                first_arr.splice(first_arr.length - second_decima_len,0,'.')
                second_arr.splice(second_arr.length - second_decima_len,0,'.')
                res_arr.splice(res_arr.length - second_decima_len,0,'')
                res_decima_len += 1
                res_arr.splice(res_arr.length - res_decima_len,0,'.')
                for (let index = 0; index < calculation_process.length; index++) {
                    const element = calculation_process[index];
                    const wei = calculation_wei[index]
                    element.splice(element.length-res_decima_len,0,'')
                    wei.splice(wei.length-res_decima_len,0,'')
                }
                first_arr.splice(first_arr.length - res_decima_len,0,'')
                second_arr.splice(second_arr.length - res_decima_len,0,'')
                //first_arr second_arr befor add null
                var first_add_num = res_arr.length - first_arr.length
                for (let index = 0; index < first_add_num; index++) {
                first_arr.unshift(null)
                }
                var second_add_num = res_arr.length - second_arr.length
                for (let index = 0; index < second_add_num; index++) {
                    second_arr.unshift(null)
                }
            }else{
            
                if (first_decima_len < second_decima_len){
                    res_arr.splice(res_arr.length - first_decima_len,0,'')   
                }else{
                    res_arr.splice(res_arr.length - second_decima_len,0,'')
                }
                res_arr.splice(res_arr.length - second_decima_len - first_decima_len,0,'')
                res_decima_len += 2
                
                res_arr.splice(res_arr.length - res_decima_len,0,'.')
                if(res_arr[0] == '.'){
                    res_arr.unshift('0')
                }
                const res_index = res_arr.indexOf('.')
                for (let index = 0; index < calculation_process.length; index++) {
                    const element = calculation_process[index];
                    const wei = calculation_wei[index]
                    if(first_decima_len<second_decima_len){
                        element.splice(element.length - first_decima_len,0,'')
                        wei.splice(wei.length - first_decima_len,0,'')
                    }else{
                        element.splice(element.length - second_decima_len,0,'')
                        wei.splice(wei.length - second_decima_len,0,'')
                    }
                
                    element.splice(element.length - second_decima_len - first_decima_len,0,'')
                    element.splice(res_index,0,'')
                
                    wei.splice(wei.length - second_decima_len - first_decima_len,0,'')
                    wei.splice(res_index,0,'')
                }
                first_arr.splice(first_arr.length - first_decima_len,0,'.')
                second_arr.splice(second_arr.length - second_decima_len,0,'.')
                var max_len = Math.max(first_arr.length,second_arr.length)
                
                for (let index = 0; index < max_len-first_arr.length; index++) {
                first_arr.unshift(null)
                }
                for (let index = 0; index < max_len-second_arr.length; index++) {
                    second_arr.unshift(null)
                }
                if(first_decima_len<second_decima_len){
                    second_arr.splice(second_arr.length - first_decima_len,0,'')
                    var second_index = second_arr.indexOf('.')
                    first_arr.splice(second_index,0,'')
                }else{
                    first_arr.splice(first_arr.length - second_decima_len,0,'')
                    var first_index = first_arr.indexOf('.')
                    second_arr.splice(first_index,0,'')
                }
                var first_add_null = res_arr.length-first_arr.length
                var second_add_nill = res_arr.length-second_arr.length
                for (let index = 0; index < first_add_null; index++) {
                    first_arr.unshift(null)
                }
                for (let index = 0; index < second_add_nill; index++) {
                    second_arr.unshift(null)
                }
                const res_add_find_index = res_arr.indexOf('.')
                first_arr[res_add_find_index] = ''
                second_arr[res_add_find_index] = ''
            }
            var new_pro = new Array()
            
            for (let index = 0; index < calculation_process.length; index++) {
                const element = calculation_process[index];
                var num_count = 0
                for (let index2 = 0; index2 < element.length; index2++) {
                    const element2 = element[index2];
                    if(element2 == '0' || element2=='' || element2==null || element2=='.'){
                        num_count+=1
                    }
                }
                if(num_count != element.length){
                    new_pro.push(calculation_process[index])
                }
            }
            // console.log(calculation_wei.length,calculation_process.length)
            // console.log(new_pro)
            // console.log(res_arr)
            returnObj.data.first_arr = second_arr
            returnObj.data.second_arr = first_arr
            returnObj.data.position_arr = calculation_wei
            returnObj.data.calculation_process = new_pro
            returnObj.data.res = res_arr
            
        }
        return returnObj
    }

    ExcTwoNumber(first_num,second_num){
        var returnObj = new Object();
        returnObj.code = 200 
        returnObj.data = new Object();
        var first_to_number,second_to_number
        try {
            first_to_number = eval(first_num)
            second_to_number = eval(second_num)
        } catch (error) {
            returnObj.code = -1
            returnObj.msg = "存在参数不为数字"
            return returnObj
        }
        if(second_to_number==0){
            returnObj.code = -1
            returnObj.msg = '除数不能为0'
            return returnObj
        }
        var calculation_process = new Array()
        var res_arr = new Array()
        var second_arr_len_ = second_num.split(".")[1]==undefined?0:second_num.split(".")[1].length
        var first_arr_old_indexOf = first_num.indexOf('.')
        var first_arr = first_num.split('')
        var second_arr = second_num.split('')
        // first_num to arr
        if(second_arr_len_>0 && first_arr_old_indexOf != -1){
            var find_first_decima_len = first_num.split('.')[1].length
            if(second_arr_len_ < find_first_decima_len){
                first_arr.splice(first_arr_old_indexOf,1)
               first_arr.splice(first_arr_old_indexOf+second_arr_len_,0,'.')
            }else if (second_arr_len_ == find_first_decima_len){
                first_arr.splice(first_arr_old_indexOf,1)
            }
            else if(second_arr_len_>find_first_decima_len){
                first_arr.splice(first_arr_old_indexOf,1)
                for (let index = 0; index < second_arr_len_-find_first_decima_len; index++) {
                    first_arr.push(0)
                }
            }
        }
        else if(second_arr_len_>0 && first_arr_old_indexOf == -1){
            for (let index = 0; index < second_arr_len_; index++) {
                first_arr.push(0)
            }
        }
        if(second_arr_len_!=0){
            var find_second_decima = second_num.indexOf('.')
            second_arr.splice(find_second_decima,1)
        }
        var first_arr_find_indexOf = first_arr.indexOf('.')
        if (first_arr_find_indexOf != -1){
            first_arr.splice(first_arr_find_indexOf,1)
        }
        var divider = parseInt(second_arr.join(''))
        if(first_to_number< second_to_number){
            while (true){
                var first_int_num = parseInt(first_arr.join(''))
                if(Math.floor(first_int_num/divider) != 0){
                    break
                }else{
                    first_arr.push(0)
                    first_arr_len_ += 1
                }
            }
        }
        var copy_arr = new Array()
        for (let index = 0; index < first_arr.length; index++) {
            const element = first_arr[index];
            copy_arr.push(element)
        }
        calculation_process.push(copy_arr)
        var divisor_arr = new Array(); //被除数数组
        var first_arr_len = first_arr.length;
        var res_arr_decima_len = 0
        for (let index = 0; index <15; index++) {
            if(index == 10){
                returnObj.code = -1
                returnObj.msg = '除不尽'
                return returnObj
            }
            const element = first_arr[index];
            if(index==0){ divisor_arr.push(element)}
            var divisor = parseInt(divisor_arr.join('')) //被除数
            var find_zero = 0;
            for (let index_zero = 0; index_zero < divisor_arr.length; index_zero++) {
                const element_zero = divisor_arr[index_zero];
                if(element_zero  != '0'){break}
                find_zero+=1;
            }
            var merchant = Math.floor(divisor/divider) //商      
            if (merchant == 0 && !res_arr.find(i => i!=0)){
                res_arr.push('0')
                if(index < first_arr_len){
                    divisor_arr.push(first_arr[index+1])   
                }else{
                    divisor_arr.push('0')    
                    
                }
                continue    
            }
            else{
                divisor_arr = (divisor % divider).toString().split('')
                var sub_arr = (merchant*divider).toString().split('') 
                if(index < first_arr_len-1){
                    if(divisor_arr.length==1 && divisor_arr[0]=='0'){
                        divisor_arr[0] = null
                    }
                    divisor_arr.push(first_arr[index+1])   
                }else{
                    if(divisor_arr.length==1 && divisor_arr[0] == '0'){
                        calculation_process.push((merchant*divider).toString().split(''))
                        calculation_process.push(divisor_arr)
                        res_arr.push(merchant.toString())
                        break
                    }
                    divisor_arr.push(0)  
                    res_arr_decima_len += 1
                }
                if(find_zero != 0){
                    for (let index = 0; index < find_zero; index++) {
                        sub_arr.unshift(null)
                    }
                }
                calculation_process.push(sub_arr)
                calculation_process.push(divisor_arr)  
                res_arr.push(merchant.toString())        
            } 
        }
        calculation_process.push([])
        var new_Arr = new Array();
        for (let index = 0; index < calculation_process.length; index+=2) {
            let new_one = new Array()
            new_one.push(calculation_process[index])
            new_one.push(calculation_process[index+1])
            new_Arr.push(new_one)
        }
        //除了最后两组步骤和第一组步骤其他后面补null
        var for_new_Arr_by_one_count = 1
        for (let index = new_Arr.length-1; index >= 0; index--) {
            if(index == new_Arr.length -2 || index == new_Arr.length -1 || index ==0){
                continue
            }
            const element = new_Arr[index];
            for (let index2 = 0; index2 < for_new_Arr_by_one_count; index2++) {
                element[0].push(null)
            }
            for (let index3 = 0; index3 < for_new_Arr_by_one_count; index3++) {
                element[1].push(null)
            }
            for_new_Arr_by_one_count += 1
        }
        var new_Arr_index_0 = new_Arr[0];
        var res_arr_len = res_arr.length;
        //第一组步骤补null
        var new_Arr_index_0_left_len = res_arr_len - new_Arr_index_0[0].length
        var new_Arr_index_0_right_len = res_arr_len - new_Arr_index_0[1].length
        for (let index = 0; index < new_Arr_index_0_left_len; index++) {
            new_Arr_index_0[0].push(null)
        }
        for (let index = 0; index < new_Arr_index_0_right_len; index++) {
            new_Arr_index_0[1].push(null)
        }
        //每组前面补null
        const New_Arr = new Array();
        for (let index = 0; index < new_Arr.length; index++) {
            var new_one_arr;
            const element = new_Arr[index];
            const left_by_one = element[0]
            const right_by_one = element[1]
            var left_zero_or_null = 0
            var  right_zero_or_null = 0
            for (let index2 = 0; index2 < left_by_one.length; index2++) {
                if(left_by_one[index2] == '0' || left_by_one[index2] == null){
                    left_zero_or_null += 1
                }
            }
            for (let index3 = 0; index3 < right_by_one.length; index3++) {
                if(right_by_one[index3] == '0' || right_by_one[index3] == null){
                    right_zero_or_null += 1
                }
            }

            
            if((left_by_one.length == left_zero_or_null && index != new_Arr.length-1 ) || (right_by_one.length == right_zero_or_null && index != new_Arr.length-1) ){
                continue
            }
            var left_by_one_count = res_arr_len - left_by_one.length
            for (let index4 = 0; index4 < left_by_one_count; index4++) {
                left_by_one.unshift(null)
            }
            var right_by_one_count = res_arr_len - right_by_one.length    
            for (let index5 = 0; index5 < right_by_one_count; index5++) {
                right_by_one.unshift(null)
            }
            if(index != new_Arr.length-1){
                new_one_arr = [left_by_one,right_by_one]
            }else{
                new_one_arr = [left_by_one]
            }
            
            New_Arr.push(new_one_arr)
        }
        //todo:
        if(first_arr_find_indexOf != -1){
            res_arr.splice(first_arr_find_indexOf,0,'.')
        }else{
            if(res_arr.length - res_arr_decima_len<res_arr.length){
                res_arr.splice(res_arr.length - res_arr_decima_len,'0','.')
            }
            
        }
        var index_res_arr = new Array
        for (let index = 0; index < res_arr_len; index++) {
            const element = res_arr[index];
            if(element != '0'){break}
            index_res_arr.push(index)
        }
        for (let index = 0; index < index_res_arr.length; index++) {
            if(res_arr[index]=='0'&& res_arr[index+1]!='.'){
                res_arr[index] = null
            }
        }
        //判读first_arr是否含有小数点以及之前的小数点位置
        if(first_arr_find_indexOf != -1){
            New_Arr[0][0].splice(first_arr_find_indexOf,0,'.')
            if(first_arr_find_indexOf != first_arr_old_indexOf){
                New_Arr[0][0].splice(first_arr_old_indexOf,0,'x')
            }
        }else if(first_arr_old_indexOf != -1){
            if(first_arr_find_indexOf == -1){
                New_Arr[0][0].splice(first_arr_old_indexOf,0,'x')
            }else{
                New_Arr[0][0].splice(first_arr_old_indexOf,0,'.')
            }
            
        }
        //计算过程重新组装' '替换'x' 和 '.'
        var find_x_indexOf = New_Arr[0][0].indexOf('x')
        var find_decima_indeOf = New_Arr[0][0].indexOf('.')
        if(find_x_indexOf != -1 || find_decima_indeOf != -1){
            for (let index = 0; index < New_Arr.length; index++) {
                const element = New_Arr[index];
                for (let index2 = 0; index2 < element.length; index2++) {
                    var res_one_ = element[index2];
                    if (index==0 && index2==0){
                        continue
                    }
                    if(find_x_indexOf != -1){
                        res_one_.splice(find_x_indexOf,0,'')
                    }
                    if(find_decima_indeOf != -1){
                        res_one_.splice(find_decima_indeOf,0,'')
                    }
                }
                
            }
        }
        var new_second_arr = second_num.split('')
        var find_second_indexOf = new_second_arr.indexOf('.')
        if(find_second_indexOf != -1){
            new_second_arr[find_second_indexOf] = 'x'
        }
        if(find_x_indexOf != -1){res_arr.splice(find_x_indexOf,0,'')}
        var find_res_arr_indexOf = res_arr.indexOf('.')
        if(find_decima_indeOf != -1 && find_res_arr_indexOf == -1){res_arr.splice(find_x_indexOf,0,'')}
        returnObj.data.res_arr = res_arr;
        returnObj.data.calculation_process = New_Arr
        returnObj.data.second_arr = new_second_arr
        return returnObj
    }

}
export { EquationClassify }
// var a = EquationClassify('22/0.02')
// var a = EquationClassify('254/3.2')
// var a = EquationClassify('12+12.5')
// var a = EquationClassify('4.6/2.3')
// var a = EquationClassify('0.075/3')
// var a = EquationClassify('124.3/11')
// var a = EquationClassify('5.405/2.35')
// console.log(a)